import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import com.code.util.CodeUtil;
import com.code.util.ICodeHelper;

public class Main {

	@SuppressWarnings("serial")
	public static void main(String[] args) throws IOException {
		String outputDir = new File(Main.class.getResource("/").getFile()).getParentFile().getAbsolutePath()+"/demo";
		List<Map<String, ?>> list = new ArrayList<Map<String, ?>>();
		list.add(new HashMap<String, Object>() {
			{
				put(ICodeHelper.SERVICE_CODE, "SERVICE_CODE");
				put(ICodeHelper.SRV_INTERFACE, "code.util.demo.sv.IXCSV");
				put(ICodeHelper.SRV_METHOD, "method");
				put(ICodeHelper.SRV_RETURN, ICodeHelper.VOID);
			}
		});

		ICodeHelper helper = new ICodeHelper() {

			@Override
			public Collection<Map<String, ?>> getSvRootParams(
					String serviceCode, String version) {
				Collection<Map<String, ?>> ret = new ArrayList<Map<String, ?>>();
				Map<String, Object> param = new HashMap<String, Object>() {
					{
						put(PARAM_ID, 1);
						put(PARAM_INOUT, "IN");
						put(PARAM_KEY, "paramName");
						put(PARAM_TYPE, "code.util.demo.Type");
					}
				};
				ret.add(param);
				return ret;
			}

			@Override
			public Map<String, Collection<Map<String, ?>>> getSvParamMapParentKey(
					String serviceCode, String version) {
				Map<String, Collection<Map<String, ?>>> ret = new HashMap<String, Collection<Map<String, ?>>>();

				ret.put(null, getSvRootParams(serviceCode, version));
				Collection<Map<String, ?>> childParams = new ArrayList<Map<String, ?>>();
				Map<String, ?> childParam = new HashMap<String, Object>() {
					{
						put(PARAM_ID, 2);
						put(PARAM_INOUT, IN);
						put(PARAM_KEY, "child");
						put(PARAM_TYPE, "int");
					}
				};
				childParams.add(childParam);
				ret.put(1 + "", childParams);
				return ret;
			}

			@Override
			public String getCodeLang() {
				return JAVA;
			}

			@Override
			public Boolean getCodeAnnotation() {
				return true;
			}

			@Override
			public String getAnnotationService(Map<?, ?> map,
					Map<String, String> importTypeMap) {
				// String serviceode = (String)
				// map.get(ICodeHelper.SERVICE_CODE);
				// String version = (String) map.get(ICodeHelper.VERSION);
				// return new StringBuffer("@")
				// .append(CodeUtil.getShortNameByImport(Service.class.getName(),
				// importTypeMap)).append("(").append("serviceCode=")
				// .append("\"").append(serviceode).append("\", ")
				// .append("version=").append("\"").append(version)
				// .append("\")\n").toString();
				return "";
			}
		};
		List<String> err = new ArrayList<String>();
		CodeUtil.generateSVCode(list, outputDir, helper, err);
		CodeUtil.generateParamTypeCode(list, new HashSet<String>(), outputDir, helper, err);
	}
}
